import 'package:flutter/material.dart';
import '../Draw/point_values.dart';
import 'coordinate.dart';

class PainterBox extends CustomPainter {

  final Paint _bgPainter = Paint()
    ..color = Colors.grey.withOpacity(0.11);//背景色
  final Paint _mainPainter = Paint()
    ..color = Colors.blue;//绘制点颜色

  final Coordinate coordinate;
  final PointVlaues points;


  PainterBox(this.points, this.coordinate):super(repaint: points);



  @override
  void paint(Canvas canvas, Size size) {
    canvas.translate(0, size.height);//整体偏移
    coordinate.paint(canvas, size);
    canvas.scale(1, -1);//画布翻转

    canvas.drawRect(Offset.zero & size, _bgPainter);
    canvas.translate(size.width/2, size.height/2); //对准中心

    for(Offset point in points.data){
      var readyPoint = Offset(point.dx + coordinate.originPointX, point.dy + coordinate.originPointY);
      double average =  (coordinate.xScaleCount+coordinate.yScaleCount)/2;
      double pointSize = 1.7*(10/average);
      canvas.drawCircle(readyPoint.scale(size.width/(2*coordinate.xScaleCount), size.height/(2*coordinate.yScaleCount)), pointSize, _mainPainter);
    }

    // Offset coo = Offset(0.2, 0.3);
    // // double xscale =size.width/coordinate.xScaleCount ;
    // // double yscale =size.height/coordinate.xScaleCount ;
    // canvas.drawCircle(coo.scale(size.width, size.height), 5, _mainPainter);
    //
    // Offset coo2 = Offset(0.25, 0.35);
    // canvas.drawCircle(coo2.scale(size.width, size.height), 5, _mainPainter);
    // // canvas.drawCircle(Offset(100, 100), 5, _mainPainter);
    // // canvas.drawCircle(Offset(150, 250), 5, _mainPainter);
    // // canvas.drawCircle(Offset(250, 250), 5, _mainPainter);
    // // canvas.drawCircle(Offset(50, 150), 5, _mainPainter);
  }

  @override
  bool shouldRepaint(covariant PainterBox oldDelegate) {
    return true;
  }
}
